home *** CD-ROM | disk | FTP | other *** search
- # markup.pl
- # ---------
- # Perl functions for HTML Markup 3.0
- #
- # History
- # 1.0 by klep (klep@cs.stanford.edu) on 5/12/99
- # 1.1 by klep (klep@cs.stanford.edu) on 7/25/99
- #
- # You may NOT distribute modified versions of this file with the HTML
- # Markup distribution. Send them to <klephacks@kagi.com> or distribute
- # them separate from the rest of HTML Markup.
- #
- # Modify this file at your own risk. Do not change any function names
- # or parameters.
-
-
-
-
- # Conversion
-
- sub ltgttobrackets {
- my($input) = @_;
-
- $input =~ s/</</gs;
- $input =~ s/>/>/gs;
-
- return $input;
- }
-
-
- # URL Recognition
-
- sub convert_url {
- my($input, $scheme) = @_;
- my($output) = "";
-
- while ($input =~ m"(.*?)$scheme([A-Za-z0-9./]*)"is)
- {
- $output = $output . "$1<a href=\"$scheme$2\">$scheme$2</a>";
- $input = $'; #'
- }
-
- return $output . $input;
- }
-
- sub http {
- my($input) = @_;
-
- my($output) = convert_url($input, "http://");
- return convert_url($output, "https://");
- }
-
- sub ftp {
- my($input) = @_;
-
- return convert_url($input, "ftp://");
- }
-
- sub news {
- my($input) = @_;
-
- return convert_url($input, "news:");
- }
-
- sub mailto {
- my($input) = @_;
-
- return convert_url($input, "mailto:");
- }
-
- sub email {
- my($input) = @_;
- my($output) = "";
-
- while ($input =~ m"([A-Za-z0-9.]*?)\@([A-Za-z0-9.]*)"is)
- {
- $output = $output . $` . "<a href=\"mailto:$1\@$2\">$1\@$2</a>"; #`
- $input = $'; #'
- }
-
- return $output . $input;
- }
-
-
- # Source Document
-
- sub makehtml {
- my($input, $headparams, $bodyparams, $tophtml) = @_;
-
- return "<HTML>\r\t<HEAD>\r\t\t$headparams\r\t</HEAD>\r<BODY $bodyparams>\r$tophtml\r" . "$input" . "\r</BODY>\r</HTML>";
- }
-
-
- # Line Breaks
-
- sub endlinesbr {
- my($input) = @_;
-
- $input =~ s/\r/<BR>\r/gs;
- $input =~ s/\n/<BR>\n/gs;
-
- return $input;
- }
-
- sub endlinesp {
- my($input) = @_;
-
- $input =~ s/\r/<P>\r/gs;
- $input =~ s/\n/<P>\n/gs;
-
- return $input;
- }
-
-
- # Misc
-
- sub linesdashed {
- my($input, $length, $thickness) = @_;
-
- $input =~ s/\r\n(-){3,}\r\n/\r\n<HR width=$length size=$thickness>\r\n/gs;
- $input =~ s/\r(-){3,}\r/\r<HR width=$length size=$thickness>\r/gs;
- $input =~ s/\n(-){3,}\n/\n<HR width=$length size=$thickness>\n/gs;
-
- return $input;
- }
-
- sub linescapital {
- my($input, $size) = @_;
-
- $rest = $input;
- while ($rest ne "") {
- ($line, $rest) = ExtractOneLine($rest);
- if (AllCaps($line)) {
- $line = "<H$size>" . ConvertCase($line) . "</H$size>";
- }
- $output = $output . $line . "\r";
- }
-
- return $output;
- }
-
-
- # Utilities
-
- sub GetOneLine {
- my($input) = @_;
-
- if ( $input =~ m/(.*?)[\r\n]/ ) {
- return $1;
- }
- return $input; # only one line long
- }
-
- sub ExtractOneLine {
- my($input) = @_;
-
- if ( $input =~ m/(.*?)\r/ ) {
- return ($1, $'); #'
- }
- return $input;
- }
-
- sub AllCaps {
- my($input) = @_;
-
- if ( $input =~ m/(.*)[a-z](.*)/ ) { # must contain no lower case letters
- return 0;
- }
- if ( $input =~ m/(.*)[A-Z](.*)/ ) { # must contain at least one letter
- return 1;
- }
- return 0;
- }
-
- sub ConvertCase {
- my($input) = @_;
-
- $input =~ tr/A-Z/a-z/;
-
- return $input;
- }
-
- sub Quote {
- return "\"";
- }
-
- 1;
-